package cn.signalpha.modules.base.service;

import cn.signalpha.core.mp.base.BaseServiceImpl;
import cn.signalpha.modules.base.entity.Protocol;
import cn.signalpha.modules.base.mapper.ProtocolMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import static cn.signalpha.common.cache.CacheNames.PROTOCOL_KEY;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class ProtocolService extends BaseServiceImpl<ProtocolMapper, Protocol> {

	@Cacheable(cacheNames = PROTOCOL_KEY, key = "#code", unless="#result==null")
	public Protocol getByCode(String code) {
		return getOne(Wrappers.<Protocol>lambdaQuery().eq(Protocol::getCode, code).last("limit 1"));
	}

	@CacheEvict(cacheNames = PROTOCOL_KEY, allEntries = true)
	public void removeCaChe() {
	}

}

